package com.loren.oauth.service;

import com.loren.oauth.data.dto.UserAuthInfo;
import lombok.AllArgsConstructor;
import org.springframework.security.core.authority.AuthorityUtils;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
@AllArgsConstructor
public class UserDetailsServiceImpl implements UserDetailsService {

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        UserAuthInfo userAuthInfo = UserAuthInfo.builder().userId("lsy_loren").userName("Loren")
                .mobile("15058407717").email("lsy_loren@163.com").password("$2a$10$XXaaFKODH6n9sKYWVuiudeVvcc9QXPFQ4lU/coDOPbMy8V4cVybuu")
                .image("http://thirdwx.qlogo.cn/mmopen/vi_32/NSoYcQkvib5W7ZNYnAesub1THckgBqic0I0aLCPZ6QPmp8R0vZ6TWWW2MzicxdUsVQZzj5EbvNuVUVqoPXO8FPSkA/132").unlock(true).enabled(true).build();

        return new SecurityUserInfo(username, userAuthInfo.getPassword(), userAuthInfo.isEnabled(), true, true,
                userAuthInfo.isUnlock(), AuthorityUtils.commaSeparatedStringToAuthorityList("insert, update"), userAuthInfo);

    }
}
